//
// Copyright (c) 2014, 保留所有权利。
//
// CstInfo.java
//
// 作    者：王红燕
// 当前版本：1.0
// 2014 下午8:05:46
//
// 
//
package com.vanke.agent.bean;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.LinkedHashSet;
import java.util.Set;

import com.vanke.agent.common.Util;

/**
 *
 */
public class CstInfo implements Serializable {
	private Set<String> mobiles = new LinkedHashSet<String>(10);
	// private boolean isCardValid = false;

	private String oriInfo; // 原始信息

	private String mobile;
	/**
	 * 客户GUID
	 */
	private long cstGUID;
	/**
	 * 客户姓名
	 */
	private String cstName;
	/**
	 * 证件号码
	 */
	private String cardId;

	private String cardId15;

	/**
	 * 性别
	 */
	private int gender;

	/**
	 * 出生日期
	 */
	private Timestamp birthday;
	private String language = "";
	private int cstType;
	private int cardType;
	private String officeTel = "";
	private String homeTel = "";
	private String fax = "";
	private String email = "";
	private String postCode = "";
	private String address = "";
	private String country = "";
	private String province = "";
	private String city = "";
	private String regitonal = "";
	private String road = "";
	private String nationality = "";
	private String nativePlace = "";
	private String srcType = "";
	private Timestamp lastModifyTime;
	private String oriGUID = "";
	private String creditEvaluate = "";
	private String cstCode = "";
	private String company = "";
	private String position = "";
	private float incoming = 0;
	private String workAddr = "";
	private String companyTel = "";
	private String race = "";
	private String religion = "";
	private String political = "";
	private int isMerried = 0;
	private Timestamp lastTouchTime;
	private String recentTouch = "";
	private Timestamp lastAssignTime;
	private String recentAssign = "";
	private Timestamp lastAppointTime;
	private String recentAppoint = "";
	private String cogniChannel = "";
	private int status = 0;
	private String memGUID = "";
	private String staffGUID = "";
	private String ownerGUID = "";
	private String tableIndex = "";
	private Timestamp createTime;
	private int level = 4;
	private String contact = "";
	private String cstSrc = "my";

	public Set<String> getMobiles() {
		return mobiles;
	}

	//
	// public void setMobiles(String mobiles) {
	// if (mobiles == null) {
	// return;
	// }
	// String[] ms = mobiles.replaceAll("-", "").split("[, ，]");
	// for (String m : ms) {
	// m = m.trim();
	// if (m.length() > 11) {
	// m = m.substring(m.length() - 11);
	// }
	// if ((Util.isMobile(m) || Util.isTel(m)) && m.length() >= 11) {
	// this.mobiles.add(m);
	// }
	// }
	// }

	public void setMobile(String mobile) {
		mobile = mobile == null ? "" : mobile.trim();
		if (mobile.length() > 11) {
			this.mobile = mobile.substring(mobile.length() - 11);
		} else {
			this.mobile = mobile;
		}
	}

	public String getMobile() {
		return mobile;
	}

	public void setCardId(String cardid) {
		this.cardId = cardid == null ? "" : cardid.trim();
		// CardID cid = new CardID(cardid);
		// if (cid.isValid()) {
		// this.isCardValid = true;
		// this.cardId = cid.to18();
		// this.cardId15 = (cardid.length() == 15) ? cardid : "";
		// setLevel(getLevel() - 2);
		// setBirthday(cid.birth().getTime() / 1000);
		// setGender(cid.sex());
		// setNativePlace(cid.nativePlace());
		// } else {
		// this.cardId = "";
		// this.cardId15 = "";
		// }
	}

	public String getCardId15() {
		return cardId15;
	}

	public void setCardId15(String cardId15) {
		cardId15 = cardId15 == null ? "" : cardId15.trim();
		try {
			this.cardId15 = new String(cardId15.getBytes("ISO-99859-1"),
					"UTF-8");
		} catch (UnsupportedEncodingException e) {
			this.cardId15 = cardId15;
		}
	}

	public void setEmail(String email) {
		this.email = (email != null && Util.isEmail(email) ? email : "");
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address == null ? "" : address;
	}

	public String getCardId() {
		return cardId;
	}

	// public boolean isCardIdValid() {
	// return isCardValid;
	// }

	public int getCardType() {
		return cardType;
	}

	public void setCardType(int cardType) {
		this.cardType = cardType;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city == null ? "" : city;
	}

	public String getCogniChannel() {
		return cogniChannel;
	}

	public void setCogniChannel(String cogniChannel) {
		this.cogniChannel = cogniChannel == null ? "" : cogniChannel;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company == null ? "" : company;
	}

	public String getCompanyTel() {
		return companyTel;
	}

	public void setCompanyTel(String companyTel) {
		this.companyTel = companyTel == null ? "" : companyTel;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country == null ? "" : country;
	}

	public String getCreditEvaluate() {
		return creditEvaluate;
	}

	public void setCreditEvaluate(String creditEvaluate) {
		this.creditEvaluate = creditEvaluate == null ? "" : creditEvaluate;
	}

	public String getCstCode() {
		return cstCode;
	}

	public void setCstCode(String cstCode) {
		this.cstCode = cstCode == null ? "" : cstCode;
	}

	public long getCstGUID() {
		return cstGUID;
	}

	public void setCstGUID(long cstGUID) {
		this.cstGUID = cstGUID;
	}

	public String getCstName() {
		return cstName;
	}

	public void setCstName(String cstName) {
		this.cstName = cstName == null ? "" : cstName.trim();
	}

	public int getCstType() {
		return cstType;
	}

	public void setCstType(int cstType) {
		this.cstType = cstType;
	}

	public String getEmail() {
		return email;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax == null ? "" : fax;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = (gender == 0 || gender == 1 || gender == 2) ? gender : 0;
	}

	public String getHomeTel() {
		return homeTel;
	}

	public void setHomeTel(String homeTel) {
		homeTel = homeTel == null ? "" : homeTel;
		if (homeTel.length() > 11) {
			this.homeTel = homeTel.substring(homeTel.length() - 11);
		} else {
			this.homeTel = homeTel;
		}
	}

	public float getIncoming() {
		return incoming;
	}

	public void setIncoming(float incoming) {
		this.incoming = incoming;
	}

	public int getIsMerried() {
		return isMerried;
	}

	public void setIsMerried(int isMerried) {
		this.isMerried = isMerried;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language == null ? "" : language;
	}

	public String getMemGUID() {
		return memGUID;
	}

	public void setMemGUID(String memGUID) {
		this.memGUID = memGUID;
	}

	public String getNationality() {
		return nationality;
	}

	public void setNationality(String nationality) {
		this.nationality = nationality == null ? "" : nationality;
	}

	public String getNativePlace() {
		return nativePlace;
	}

	public void setNativePlace(String nativePlace) {
		this.nativePlace = nativePlace == null ? "" : nativePlace;
	}

	public String getOfficeTel() {
		return officeTel;
	}

	public void setOfficeTel(String officeTel) {
		this.officeTel = officeTel == null ? "" : officeTel;
	}

	public String getOriGUID() {
		return oriGUID;
	}

	public void setOriGUID(String oriGUID) {
		this.oriGUID = oriGUID;
	}

	public String getOwnerGUID() {
		return ownerGUID;
	}

	public void setOwnerGUID(String ownerGUID) {
		this.ownerGUID = ownerGUID;
	}

	public String getPolitical() {
		return political;
	}

	public void setPolitical(String political) {
		this.political = political == null ? "" : political;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = (postCode != null && postCode.matches("\\d{6}")) ? postCode
				: "";
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province == null ? "" : province;
	}

	public String getRace() {
		return race;
	}

	public void setRace(String race) {
		this.race = race == null ? "" : race;
	}

	public String getRecentAppoint() {
		return recentAppoint;
	}

	public void setRecentAppoint(String recentAppoint) {
		this.recentAppoint = recentAppoint;
	}

	public String getRecentAssign() {
		return recentAssign;
	}

	public void setRecentAssign(String recentAssign) {
		this.recentAssign = recentAssign;
	}

	public String getRecentTouch() {
		return recentTouch;
	}

	public void setRecentTouch(String recentTouch) {
		this.recentTouch = recentTouch == null ? "" : recentTouch;
	}

	public String getRegitonal() {
		return regitonal;
	}

	public void setRegitonal(String regitonal) {
		this.regitonal = regitonal == null ? "" : regitonal;
	}

	public String getReligion() {
		return religion;
	}

	public void setReligion(String religion) {
		this.religion = religion == null ? "" : religion;
	}

	public String getRoad() {
		return road;
	}

	public void setRoad(String road) {
		this.road = road == null ? "" : road;
	}

	public String getSrcType() {
		return srcType;
	}

	public void setSrcType(String srcType) {
		this.srcType = srcType;
	}

	public String getStaffGUID() {
		return staffGUID;
	}

	public void setStaffGUID(String staffGUID) {
		this.staffGUID = staffGUID;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getWorkAddr() {
		return workAddr;
	}

	public void setWorkAddr(String workAddr) {
		this.workAddr = workAddr == null ? "" : workAddr;
	}

	public String getTableIndex() {
		return tableIndex;
	}

	public void setTableIndex(String tableIndex) {
		this.tableIndex = tableIndex;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getOriInfo() {
		return oriInfo;
	}

	public void setOriInfo(String oriInfo) {
		this.oriInfo = oriInfo;
	}

	public Timestamp getBirthday() {
		return birthday;
	}

	public void setBirthday(Timestamp birthday) {
		this.birthday = birthday;
	}

	public Timestamp getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(Timestamp lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public Timestamp getLastTouchTime() {
		return lastTouchTime;
	}

	public void setLastTouchTime(Timestamp lastTouchTime) {
		this.lastTouchTime = lastTouchTime;
	}

	public Timestamp getLastAssignTime() {
		return lastAssignTime;
	}

	public void setLastAssignTime(Timestamp lastAssignTime) {
		this.lastAssignTime = lastAssignTime;
	}

	public Timestamp getLastAppointTime() {
		return lastAppointTime;
	}

	public void setLastAppointTime(Timestamp lastAppointTime) {
		this.lastAppointTime = lastAppointTime;
	}

	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		contact = contact == null ? "" : contact.trim();
		this.contact = contact;
		String[] cs = contact.split(";");
		Set<String> set = new LinkedHashSet<String>();
		for (String c : cs) {
			set.add(c.trim());
		}
		this.contact = "";
		for (String s : set) {
			this.contact += s + ";";
		}
	}

	public String getCstSrc() {
		return cstSrc;
	}

	public void setCstSrc(String cstSrc) {
		this.cstSrc = cstSrc;
	}

	@Override
	public String toString() {
		return String.format(
				"CstInfo:" //
						+ "uid=%s,"       		// cstGUID,
						+ "oriGUID=%s,"         // oriGUID,
						+ "cardid=%s,"          // cardId ,
						+ "mobile=%s,"         	// 
						+ "homeTel=%s,"         	// 
						+ "officeTel=%s,"         	// 
						+ "contact/tellist=%s," + "modify=%s",         	// 
				cstGUID,     //
				oriGUID,     //
				cardId, 	 //
				mobile, homeTel, officeTel, contact,
				lastModifyTime == null ? "" : Util.formatDate(lastModifyTime));//
	}
}
